package aod.android.com.bernay.live.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.io.IOException;
import java.util.List;

import aod.android.com.bernay.R;
import aod.android.com.bernay.http.BernayApi;
import aod.android.com.bernay.http.BernayCallback;
import aod.android.com.bernay.live.bean.LiveHFBean;
import chen.lion.hilib.image.ImageLoader;

public class InfoAdapter extends BaseAdapter {

    public List<LiveHFBean> mDatas;

    public Context mContext;

    public InfoAdapter(List<LiveHFBean> mDatas, Context mContext) {
        this.mDatas = mDatas;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public LiveHFBean getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.hf_item,null);

        ImageView userImage = convertView.findViewById(R.id.user_image);
        TextView userName = convertView.findViewById(R.id.user_name);
        TextView oName = convertView.findViewById(R.id.oname);
        LinearLayout mOlayout = convertView.findViewById(R.id.hf_layout);
        TextView oContent = convertView.findViewById(R.id.ocontent);

        TextView content = convertView.findViewById(R.id.content);

        TextView date = convertView.findViewById(R.id.date);
        final TextView love = convertView.findViewById(R.id.dianzan);
        final ImageView loveiv = convertView.findViewById(R.id.dianzaniv);

        convertView.findViewById(R.id.dinazan_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BernayApi.http().postLove("123", "123", "123", new BernayCallback() {
                    @Override
                    public void onJsonData(String json) {
                        loveiv.setImageResource(R.drawable.icon_little_zan_select);
                        love.setText("已赞");
                    }

                    @Override
                    public void onHttpFailure(IOException e) {

                    }
                });
            }
        });

        ImageLoader.with(mContext).load(getItem(position).getUserUrl(),userImage);
        userName.setText(getItem(position).getUserName());
        if(!TextUtils.isEmpty(getItem(position).getoName())){
            mOlayout.setVisibility(View.VISIBLE);
            oName.setText(getItem(position).getoName());
            oContent.setText(getItem(position).getoContent());
        }else{
            mOlayout.setVisibility(View.GONE);
        }

        content.setText(getItem(position).getContent());
        date.setText(getItem(position).getDate());

        return convertView;
    }
}
